package com.dlc.longweisheng.chongdianxian.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.dlc.longweisheng.chongdianxian.R;
import com.dlc.longweisheng.chongdianxian.pub.Constant;
import com.dlc.longweisheng.chongdianxian.pub.base.BaseActivity;
import com.dlc.longweisheng.chongdianxian.pub.net.Urls;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dlc.commonlibrary.utils.PrefUtil;

public class ReviseHostActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.et_name)
    EditText etName;

    @Override
    public int getLayoutId() {
        return R.layout.activity_revise_host;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        tvTitle.setText("修改服务器url");
        etName.setText(PrefUtil.getDefault().getString("host", Constant.DEFAULT_HOST));
    }

    @OnClick({R.id.tv_back, R.id.btn_post})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
            case R.id.btn_post:
                String name = etName.getText().toString().trim();
                if (name.equals("")) {
                    showOne(etName.getHint().toString());
                    return;
                }
                PrefUtil.getDefault().saveString("host", name);
                Urls.BASE_URL = /*"http://" +*/ PrefUtil.getDefault().getString("host", Constant.DEFAULT_HOST);
                showOne("修改成功！");
                finish();
                break;
        }
    }
}
